package com.xinnet.mms.dept.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.xinnet.core.dao.impl.BaseDaoImpl;
import com.xinnet.mms.dept.dao.DeptDao;
import com.xinnet.mms.entity.Customer;
import com.xinnet.mms.entity.Dept;
@Repository("deptDao")
public class DeptDaoImpl extends BaseDaoImpl<Dept, Long> implements DeptDao{
	
	public List<Dept> getDeptList(){
		List<Dept> deptList = super.getSqlSession().selectList("Dept.getDeptList");
		if(deptList!=null && deptList.size()==0){
			deptList=null;
		}
		return deptList;
	}
	public void addDept(Dept dept){
		super.getSqlSession().insert("Dept.addDept",dept);
	}
	
	public void updateDept(Dept dept){
		super.getSqlSession().update("Dept.updateDept",dept);
	}
	
	public void delDeptById(String deptId){
		super.getSqlSession().delete("Dept.delDeptById",deptId);
	}
	
	public Dept getDeptByName(String deptName){
		Dept dept = super.getSqlSession().selectOne("Dept.getDeptByName",deptName);
		return dept;
	}
	
	public Dept getDeptByDeptId(String deptId){
		Dept dept = super.getSqlSession().selectOne("Dept.getDeptByDeptId",deptId);
		return dept;
	}
	
	public Dept isCanUseTheDeptName(String dname){
		Dept dept = super.getSqlSession().selectOne("Dept.isCanUseTheDeptName",dname);
		return dept;
	}
	
/*	public List<Dept> getDeptListExceptRootNode(){
		List<Dept> deptList = super.getSqlSession().selectList("Dept.getDeptListExceptRootNode");
		if(deptList!=null && deptList.size()==0){
			deptList=null;
		}
		return deptList;
	}*/
	
	
	public Dept getDeptByEmpNo(String empNo){
		Dept dept = super.getSqlSession().selectOne("Dept.getDeptByEmpNo",empNo);
		return dept;
	}
	
	/**
	 * 通过区域ID/产品CODE取得部门
	 */
	@Override
	public Dept getDeptByProductCodeAndAreaId(Customer customer) throws SQLException {
		return this.getSqlSession().selectOne("Dept.getDeptByProductCodeAndAreaId",customer);
	}
	
	public List<Dept> getDeptListByDeptIdStr(String deptIdStr){
		return this.getSqlSession().selectList("Dept.getDeptListByDeptIdStr",deptIdStr);
	}
	/**
	 * 根据产品code 重置部门内所有员工的可分配标签
	 */
	@Override
	public void resetAllotLabelByProductCode(String productCode) throws SQLException {
		this.getSqlSession().update("Dept.resetAllotLabelByProductCode",productCode);
	}
	
	/**
	 * 添加部门子部门关系表记录
	 */
	@Override
	public void addDeptChildRelation(Dept dept) throws SQLException {
		this.getSqlSession().insert("Dept.addDeptChildRelation",dept);
	}
	
	/**
	 * 查询参数中子部门ID和部门ID在表中的个数
	 */
	@Override
	public Integer getDeptRelationByDeptnoAndChildId(Dept dept) throws SQLException {
		return this.getSqlSession().selectOne("Dept.getDeptRelationByDeptnoAndChildId",dept);
	}
	
	/**
	 * 
	 *
	 * 功能描述：查询公司名称
	 * 
	 * @author yanlvshui
	 *
	 * @throws 2014年8月11日
	 *
	 */
	public String getCompanyNameByCompId(String companyId) throws SQLException {
		return this.getSqlSession().selectOne("Dept.getCompanyNameByCompId",companyId);
	}
	@Override
	public List<Dept> getDeptByString() {
		List<Dept> deptList = super.getSqlSession().selectList("Dept.getDeptByString");
		if(deptList!=null && deptList.size()==0){
			deptList=null;
		}
		return deptList;
	}
}
